import 'package:flutter/material.dart';

class BottomNavigationBarDemo extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _BottomNavigationBarDemoState();
  }
}

class _BottomNavigationBarDemoState extends State<BottomNavigationBarDemo> {


  int _currentIndex = 0;

  //回调
  void _onTagHandler(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
      //如果导航栏的个数大于等于4个，底部颜色会变化，需要设置类型
      type: BottomNavigationBarType.fixed,
      //设置激活状态下的颜色
      fixedColor: Colors.black,
      currentIndex: _currentIndex,
      onTap: _onTagHandler,
      items: [
        BottomNavigationBarItem(
            icon: Icon(Icons.explore), title: Text('Explore')),
        BottomNavigationBarItem(
            icon: Icon(Icons.history), title: Text('History')),
        BottomNavigationBarItem(
            icon: Icon(Icons.list), title: Text('List ')),
        BottomNavigationBarItem(
            icon: Icon(Icons.person), title: Text('My')),
      ],
    );
  }

}